package com.lovo.controller;


import com.lovo.bean.Supplierproduct;
import com.lovo.service.ISupplierproductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-09-17
 */
@RestController
@RequestMapping("supplier/supplierproduct")
public class SupplierproductController {

    @Autowired
    ISupplierproductService supplierproductService;

    @GetMapping("findAllSupProduct/{supId}")
    public List<Supplierproduct> findAllSupProduct(@PathVariable("supId") int supId) {
        return supplierproductService.findAllProductBySupId(supId);
    }

    @DeleteMapping("del/{supplierProductId}")
    public String delProduct(@PathVariable("supplierProductId") int supplierProductId) {
        supplierproductService.delProduct(supplierProductId);
        return "ok";
    }

    @PutMapping("updateProductPriceById/{productId}/{price}")
    public String updateProductPriceById(@PathVariable("productId") Integer productId, @PathVariable("price") Integer price) {
        supplierproductService.updateProductPriceById(productId, price);
        return "ok";
    }

    @GetMapping("addProduct")
    public String addProduct(Supplierproduct supplierproduct){
        supplierproductService.addProduct(supplierproduct);
        return "ok";
    }

    @GetMapping("findByName/{productName}/{supId}")
    public Supplierproduct addProduct(@PathVariable("productName")String productName,
                             @PathVariable("supId")Integer supId ){

        return supplierproductService.findByName(productName,supId);
    }

}
